package io.github.enbool.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import io.github.enbool.domain.User;
import io.github.enbool.service.UserService;


@Component
public class OAuth2UserDetailsService implements UserDetailsService {
	
	@Autowired 
	private UserService userService;

	@Override
	public UserDetails loadUserByUsername(String username)   {
		
		User user = (User) userService.loadUser(username);
		
		if(user == null) {
			throw new UsernameNotFoundException("用户不存在");
		}

		return user;
	}

}
